home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!news
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Help with Boolean class and templates
- Date: 4 Jan 1996 19:32:40 GMT
- Organization: Datalytics, Inc
- Message-ID: <4cha0o$ldg@gold.datalytics.com>
- References: <4bpb9t$dsh@onlink3.onlink.net> <30E150AB.1ACF@cmt.lpr.mail.carel.fi> <ZLNMKWP.95Dec27142935@bridge.bst.bls.com>
- NNTP-Posting-Host: pc071.datalytics.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- zlnmkwp@bridge.bst.bls.com (Alun Champion) wrote:
- >In article <30E150AB.1ACF@cmt.lpr.mail.carel.fi> Ari Lukumies <aril@cmt.lpr.mail.carel.fi> writes:
- >: wfss16@onlink.net wrote:
- >
- >: [snip]
- >:> Boolean Flag(1);
- >:>
- >:> if(Flag)
- >:> yada yada yada...
- >:>
- >:> What I mean is, can you get an object to do a default
- >:> function so I don't have to do this:
- >:>
- >:> if(Flag.GetValue())
- >: [snip]
- >
- >: You could, in your Boolean class, implement the operator int()
- >[snip]
- >
- >if (..) will also accept void* conversions too. I have noticed that
- >many implementations use void* as the standard means of converting for if
- >statements and return 'this' if the object is valid.
- >
-
- FYI, here is how you would declare those functions. I use
- these same functions to allow ready detection of error states
- in non-boolean classes. (BTW, these functions are derived
- from those in ios.)
-
- class Boolean
- {
- public:
- DI_BOOLEAN operator !(void) const;
- operator void*() const;
- ...
- };
-
- // Function: operator !()
- // Description: Indicates if there is an error in this
- // object. It can be used like this:
- // Boolean b(...);
- // if (!b) // if there is an error
- // {
- // ...
- // }
- //
- // Modification History (date, name, description):
-
- inline
- int Boolean::operator !(void) const
- {
- return m_Flag != 1;
- }
-
- // Function: operator void*()
- // Description: Indicates if there is no error in this
- // object. It can be used like this:
- // Boolean b(...);
- // if (b) // if there is no error
- // {
- // ...
- // }
- //
- // NOTE: The pointer is never valid; it serves only to
- // indicate the lack of errors.
- //
- // Modification History (date, name, description):
-
- inline
- Boolean::operator void*(void) const
- {
- return (void*)m_Flag;
- }
-
- I didn't bother changing all the comments. They are from my
- DIErrorState class from which I inherit many others to provide
- error state checking. Thus, references to errors aren't
- germane to a boolean class.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc.
- (513)226-7700
- stew@datalytics.com
-
-
-